package maze;

/**
 * A class representing the location of an object.
 * A location consists of the x and y coordinates and the location is in cm
 */
public class Location {
	public double x;
	public double y;
	
	/**
	 * Updates this location, given another location.
	 * 
	 * @param loc
	 * 			The new location
	 */
	public void updateLocation(Location loc){
		setX(loc.getX());
		setY(loc.getY());
	}
	
	/**
	 * Updates this location, given a set of coordinates
	 * 
	 * @param x
	 * 			The new x coordinate
	 * @param y
	 * `		The new y coordinate
	 */
	public void updateLocation(double x, double y){
		setX(x);
		setY(y);
	}
	
	public Location(double x, double y){
		setX(x);
		setY(y);
	}
	
	private void setX(double x){
		this.x = x;
	}
	
	private void setY(double y){
		this.y = y;
	}
	
	public double getX(){
		return this.x;
	}
	
	public double getY(){
		return this.y;
	}
	
	@Override
	public boolean equals(Object other){
		if(other instanceof Location){
			Location loc = (Location) other;
			return (loc.getX() == this.getX()) && (loc.getY() == this.getY());
		}
		return false;
	}
	
	@Override
	public int hashCode(){
		double result = 0;
		double c = getX();
		result = 37 * result + c;
		c = getY();
		result += c;
		return (int) result;
	}
	
	@Override
	public String toString(){
		return "" + getX() + "," + getY();
	}
	
	public static Location getLocationInDirection(Location location, Direction direction){
		switch(direction){
		case NORTH:
			return new Location(location.getX(),location.getY()+1);
		case EAST: 
			return new Location(location.getX()+1,location.getY());
		case SOUTH: 
			return new Location(location.getX(),location.getY()-1);
		case WEST: 
			return new Location(location.getX()-1,location.getY());
		}
		return null;	
	}
}
